#include <cppunit/config/SourcePrefix.h>

#include "ResultTable.h"
#include "TestResultTable.h"

void ResultTableTest::setUp() {
	std::cout << "Test ResultTable setUp()\n";
}

void ResultTableTest::tearDown() {
}

// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( ResultTableTest );

// Tests the constructor
void ResultTableTest::testConstructor() {
	ResultTable resultTable;
}

// Tests the addSynonym function
void ResultTableTest::testAddSynonym() {
	ResultTable resultTable;
	
	CPPUNIT_ASSERT(true == resultTable.addSynonym("a"));
	CPPUNIT_ASSERT(true == resultTable.addSynonym("a")); // adding an existing synonym returns false
	CPPUNIT_ASSERT(false == resultTable.addSynonym("")); // adding an empty synonym returns false
}


/*
// Tests the addAttributeRequirement function
void ResultTableTest::testAddAttributeRequirement() {
	ResultTable resultTable;

	CPPUNIT_ASSERT(true == resultTable.addAttributeRequirement("a", "stmt# = 2"));
	CPPUNIT_ASSERT(false == resultTable.addAttributeRequirement("", "stmt# = 2")); // adding an empty synonym returns false
	CPPUNIT_ASSERT(false == resultTable.addAttributeRequirement("b", "")); // adding empty requirement returns false
}

// Tests the addResult function
void ResultTableTest::testAddResult() {
	ResultTable resultTable;

	// Add a synonym first
	CPPUNIT_ASSERT(true == resultTable.addSynonym("a"));
	
	// Test the addResult function
	CPPUNIT_ASSERT(true == resultTable.addResult("a", "1"));
	CPPUNIT_ASSERT(true == resultTable.addResult("a", "2"));
	CPPUNIT_ASSERT(false == resultTable.addResult("b", "1")); // b doesn't exist, so should return false
}

*/

// Tests the getSynonymAtIndex function
void ResultTableTest::testGetSynonymAtIndex() {
	ResultTable resultTable;

	// Add some synonyms
	CPPUNIT_ASSERT(true == resultTable.addSynonym("a")); // added to index 0
	CPPUNIT_ASSERT(true == resultTable.addSynonym("b")); // added to index 1

	// Try to get them
	CPPUNIT_ASSERT("a" == resultTable.getSynonymAtIndex(0));
	CPPUNIT_ASSERT("b" == resultTable.getSynonymAtIndex(1));
	CPPUNIT_ASSERT("" == resultTable.getSynonymAtIndex(2)); // no synonym at index 2, so empty string returned
}


/*
// Tests the getAttributeRequirementsForSynonym function
void ResultTableTest::testGetAttributeRequirementsForSynonym() {
	ResultTable resultTable;

	// Add some synonyms with attribute requirements
	CPPUNIT_ASSERT(true == resultTable.addAttributeRequirement("a", "stmt# = 2"));
	CPPUNIT_ASSERT(true == resultTable.addAttributeRequirement("a", "stmt# = 3"));

	// Try to get them
	std::vector<std::string> attributeReqs = resultTable.getAttributeRequirementsForSynonym("a");
	CPPUNIT_ASSERT(2 == attributeReqs.size());
	CPPUNIT_ASSERT("stmt# = 2" == attributeReqs.at(0));
	CPPUNIT_ASSERT("stmt# = 3" == attributeReqs.at(1));

	// Check that empty/non-existant synonym will return empty vector
	CPPUNIT_ASSERT(0 == resultTable.getAttributeRequirementsForSynonym("").size());
	CPPUNIT_ASSERT(0 == resultTable.getAttributeRequirementsForSynonym("b").size());
}

// Tests the getResultsForSynonym function
void ResultTableTest::testGetResultsForSynonym() {
	ResultTable resultTable;

	// Add a synonym
	CPPUNIT_ASSERT(true == resultTable.addSynonym("a"));

	// Add some results
	CPPUNIT_ASSERT(true == resultTable.addResult("a", "1"));
	CPPUNIT_ASSERT(true == resultTable.addResult("a", "2"));

	// Try to get them
	std::vector<std::string> results = resultTable.getResultsForSynonym("a");
	CPPUNIT_ASSERT(2 == results.size());
	CPPUNIT_ASSERT("1" == results.at(0));
	CPPUNIT_ASSERT("2" == results.at(1));

	// Check that empty/non-existant synonym will return empty vector
	CPPUNIT_ASSERT(0 == resultTable.getResultsForSynonym("").size());
	CPPUNIT_ASSERT(0 == resultTable.getResultsForSynonym("b").size());
}

*/

// Tests the getNumberOfEntries function
void ResultTableTest::testGetNumberOfEntries() {
	ResultTable resultTable;

	// Add a few synonyms
	CPPUNIT_ASSERT(true == resultTable.addSynonym("a"));
	CPPUNIT_ASSERT(true == resultTable.addSynonym("b"));
	CPPUNIT_ASSERT(true == resultTable.addSynonym("c"));
	CPPUNIT_ASSERT(true == resultTable.addSynonym("c")); 
	// Check the number of entries
	CPPUNIT_ASSERT(4 == resultTable.getNumberOfEntries());
}

void ResultTableTest::testReplaceSynonym() {
	ResultTable resultTable;

	// Add a few synonyms
	CPPUNIT_ASSERT(true == resultTable.addSynonym("a"));
	CPPUNIT_ASSERT(true == resultTable.addSynonym("b"));
	CPPUNIT_ASSERT(true == resultTable.addSynonym("c"));
	CPPUNIT_ASSERT(true == resultTable.addSynonym("c")); 

	resultTable.replaceSynonym("d", "c");
	CPPUNIT_ASSERT(4 == resultTable.getNumberOfEntries());
	CPPUNIT_ASSERT("d" == resultTable.getSynonymAtIndex(2));
	CPPUNIT_ASSERT("d" == resultTable.getSynonymAtIndex(3));

	resultTable.replaceSynonym("a", "d");
	CPPUNIT_ASSERT("a" == resultTable.getSynonymAtIndex(2));

	resultTable.replaceSynonym("q", "e");
	CPPUNIT_ASSERT("a" == resultTable.getSynonymAtIndex(3));

}

